import java.util.Random;
import java.util.Scanner;

public class Test {
    public static int max(int a, int b) {
        return a > b ? a : b;
    }

    public static int max(int a, int b, int c) {
        return max(a, max(b, c));
    }

    public static int fac(int n) {
        int ret = 1;
        for (int i = 1; i <= n; i++) {
            ret *= i;
        }
        return ret;
    }

    public static int facSum(int n) {
        int sum = 0;
        for (int i = 1; i <= n; i++) {
            sum += fac(i);
        }
        return sum;
    }

    public static int fib(int n) {
        //1 1 2 3 5 8 13
        int fib1 = 1, fib2 = 1, fib3 = 1;
        for (int i = 3; i <= n; i++) {
            fib3 = fib1 + fib2;
            fib1 = fib2;
            fib2 = fib3;
        }
        return fib3;
    }

    public static void main16(String[] args) {
        /*int a = 30, b = 20, c = 40;
        System.out.println(max3(a, b, c));*/
        //System.out.println(fac(4));
        //System.out.println(facSum(4));
        System.out.println(fib(1));
    }

    //java中的方法注意事项：
    //修饰符：现阶段直接使用 public static 固定搭配
    //返回值类型：没有返回值写 void 要有返回值则返回值类型必须与要返回的实体一致
    //方法名称：采用小驼峰(第一个单词小写其余单词首字母大写)
    //java中方法必须写到类中
    //java中没有声明一说(也就是只要定义了这个方法就能用)

    //方法的重载：
    //方法名相同并且满足 参数的个数 数据类型 参数的顺序 中的至少一个不同才能够重载
    //1.返回类型不同不够成重载 2.参数名不同不够成重载
    public static void main15(String[] args) {
        System.out.println(add(1, 2));
        System.out.println(add(1, 1.1));
        System.out.println(add(1.1, 2.2));
        System.out.println(add(1.2, 1));
        System.out.println(add(1, 2, 3));
    }

    public static int add(int a, int b) {
        return a + b;
    }

    public static double add(double a, double b) {//数据类型不同
        return a + b;
    }

    public static int add(int a, int b, int c) {//个数不同
        return a + b + c;
    }

    public static double add(int a, double b) {
        return a + b;
    }

    public static double add(double a, int b) {//顺序不同
        return a + b;
    }
    //报错 重载与参数名无关
    /*public static int add(int x,int y){
        return x+y;
    }*/
    //报错 重载与返回类型无关
    /*public static double add(int a,int b){
        return (double)(a+b);
    }*/

    public static void main14(String[] args) {
        //求一个整数在内存中有多少个比特位为1
//        Random rand = new Random();
//        int n = rand.nextInt(1025);
        int n = -1;
        int cnt = 0;

        //方法1
        /*for (int i = 0; i < 32; i++) {
            if (((n >> i) & 1) == 1) {
                cnt++;
            }
        }*/

        //方法2
        /*System.out.print(n + " 有 ");
        int tmp=n
        while (tmp != 0) {
            if ((tmp & 1) != 0) {
                cnt++;
            }
            tmp = tmp >>> 1;//必须是无符号右移 不然负数就会死循环
        }*/

        //方法3
        int tmp = n;
        while (tmp != 0) {
            tmp = tmp & (tmp - 1);
            cnt++;
        }
        System.out.println(n + " 有 " + cnt + " 个1");
    }

    public static void main13(String[] args) {
        Random rand = new Random();
        int n = rand.nextInt(1025);
        System.out.println(n + "的奇数位的二进制序列：");
        int tmp = n;
        while (tmp != 0) {
            System.out.print(tmp % 2);
            tmp = tmp >>> 2;
        }
        System.out.println("\n" + n + "的偶数位的二进制序列：");
        tmp = n >>> 1;
        while (tmp != 0) {
            System.out.print(tmp % 2);
            tmp = tmp >>> 2;
        }
    }

    public static void main12(String[] args) {
        //求出0-999之间的所有水仙花数(各位的3次方和为该数本身)
        for (int i = 0; i <= 999; i++) {
            int tmp = i;
            int sum = 0;
            while (tmp != 0) {
                int x = tmp % 10;
                sum += x * x * x;
                tmp /= 10;
            }
            if (sum == i) {
                System.out.println(i);
            }
        }
    }

    public static void main11(String[] args) {
        //求出两个正整数的最大公约数
        Random rand = new Random();
        int a = rand.nextInt(1000) + 2;
        int b = rand.nextInt(1000) + 2;
        System.out.print(a + "与" + b + "的最大公约数是:");
//        System.out.println(a);
//        System.out.println(b);
        int r = a % b;
        while (r != 0) {
            a = b;
            b = r;
            r = a % b;
        }
        System.out.println(b);
    }

    public static void main10(String[] args) {
        //输出乘法口诀表
        for (int i = 1; i <= 9; i++) {
            for (int j = 1; j <= i; j++) {
                System.out.printf("%d*%d=%-3d", j, i, i * j);
            }
            System.out.println("");
        }
    }

    public static void main9(String[] args) {
        //输出1000-2000之间所有的闰年
        for (int i = 1000; i <= 2000; i++) {
            if ((i % 400 == 0) || (i % 100 != 0 && i % 4 == 0)) {
                System.out.println(i);
            }
        }
    }

    public static void main8(String[] args) {
        //大印1-100之间所有的素数
        for (int i = 2; i <= 100; i++) {
            boolean flag = true;
            for (int j = 2; j < i; j++) {
                if (i % j == 0) {
                    flag = !flag;
                    break;
                }
            }
            if (flag) {
                System.out.println(i);
            }
        }
    }

    public static void main7(String[] args) {
        //判定一个数是否是素数
        Random rand = new Random();
        //生成随机数
        int num = rand.nextInt(100) + 1;//[1-100]
        //int num = 85;
        boolean flag = true;
        for (int i = 2; i < num; i++) {
            if (num % i == 0) {
                flag = !flag;
                break;
            }
        }
        if (flag) {
            System.out.println(num + "是一个素数");
        } else {
            System.out.println(num + "不是一个素数");
        }
    }

    public static void main6(String[] args) {
        //根据年龄来打印当前年龄的人是少年(低于18),青年(19-28),中年(29-55),老年(56以上)
        int age = 70;
        if (age <= 18) {
            System.out.println(age + "岁属于少年");
        } else if (age <= 28) {
            System.out.println(age + "岁属于青年");
        } else if (age <= 55) {
            System.out.println(age + "岁属于中年");
        } else {
            System.out.println(age + "岁属于老年");
        }
    }

    public static void main5(String[] args) {
        //猜数字
        Random rand = new Random();
        //生成随机数
        int x = rand.nextInt(100) + 1;//[1-100]
        int input = -1;
        Scanner in = new Scanner(System.in);
        do {
            System.out.println("猜猜这个数(输入0退出)：");
            input = in.nextInt();//读入数字
            if (input == 0) {
                break;
            }
            if (input > x) {
                System.out.println("大了");
            } else if (input < x) {
                System.out.println("小了");
            } else {
                System.out.println("猜对了!!!");
                x = rand.nextInt(100) + 1;//[1-100]
            }
        } while (input != 0);
        System.out.println("这个数是：" + x);
    }

    public static void main4(String[] args) {
        //1-100中既能被3整除又能被5整除的所有数
        int i = 0;
        while (i < 100) {
            i++;
            if (i % 3 != 0) {
                continue;
            }
            if (i % 5 != 0) {
                continue;
            }
            System.out.println(i);
        }
    }

    public static void main3(String[] args) {
        //计算1-5的阶乘的和
        int i = 1;
        int sum = 0;
        while (i <= 5) {
            int n = 1;
            int fac = 1;
            while (n <= i) {
                fac *= n;
                n++;
            }
            sum += fac;
            i++;
        }
        System.out.println(sum);
    }

    public static void main2(String[] args) {
        //1-100的和、奇数的和、偶数的和
        int sum = 0, oddSum = 0, evenSum = 0;
        int i = 1;
        while (i <= 100) {
            sum += i;
            if (i % 2 == 0) evenSum += i;
            else oddSum += i;
            i++;
        }
        System.out.println("sum 1-100:" + sum);
        System.out.println("odd sum 1-100:" + oddSum);
        System.out.println("even sum 1-100:" + evenSum);
    }

    public static void main1(String[] args) {
        //java中 long float double boolean 不能作为switch 的匹配参数
        String s = "one";
        switch (s) {
            case "one":
                System.out.println(1);
                break;
            case "two":
                System.out.println(2);
                break;
            default:
                System.out.println("default");
                break;
        }
    }
}
